package com.zs.admin.controller.wisdbook;

import com.zs.admin.aop.Log;
import com.zs.admin.service.wisdbook.IWisdbookPageService;
import com.zs.admin.validate.wisdbook.WisdbookPagePLUpdateValidate;
import com.zs.admin.validate.commons.IdValidate;
import com.zs.admin.validate.wisdbook.WisdbookPageCreateValidate;
import com.zs.admin.validate.wisdbook.WisdbookPageUpdateValidate;
import com.zs.admin.validate.wisdbook.WisdbookPageSearchValidate;
import com.zs.admin.vo.wisdbook.WisdbookPageDetailVo;
import com.zs.common.core.AjaxResult;
import com.zs.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/wisdbook/page")
@Api(tags = "智书书页管理")
public class WisdbookPageController {

    @Resource
    IWisdbookPageService iWisdbookPageService;

    @PostMapping("/list")
    @ApiOperation(value="智书书页列表")
    public AjaxResult list(@Validated @RequestBody WisdbookPageSearchValidate searchValidate) {
        AjaxResult result = iWisdbookPageService.list( searchValidate);
        return result;
    }

    @PostMapping("/detail")
    @ApiOperation(value="智书书页详情")
    public AjaxResult<WisdbookPageDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        WisdbookPageDetailVo detail = iWisdbookPageService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "智书书页新增")
    @PostMapping("/add")
    @ApiOperation(value="智书书页新增")
    public AjaxResult<Object> add(@Validated @RequestBody WisdbookPageCreateValidate createValidate) {
        iWisdbookPageService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "智书书页编辑")
    @PostMapping("/edit")
    @ApiOperation(value="智书书页编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody WisdbookPageUpdateValidate updateValidate) {
        iWisdbookPageService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "智书书页删除")
    @PostMapping("/del")
    @ApiOperation(value="智书书页删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iWisdbookPageService.del(idValidate.getId());
        return AjaxResult.success();
    }

    @Log(title = "智书书页页码批量更新")
    @PostMapping("/update_pagenum")
    @ApiOperation(value="智书书页页码批量更新")
    public AjaxResult<Object> update_pagenum(@Validated @RequestBody WisdbookPagePLUpdateValidate plUpdateValidate) {
        iWisdbookPageService.pl_edit(plUpdateValidate);
        return AjaxResult.success();
    }
}
